//
//  GMShareManager.m
//  ShareTest
//
//  Created by 小熊 on 2018/9/20.
//  Copyright © 2018年 小熊. All rights reserved.
//

#import "GMShareManager.h"

#define YouMenAppKey @"5837f8644544cb6711000bb5"//友盟appkey
#define ShareWXAppId @"wxab61e7eb14beca73"
#define ShareWXAppSecret @"a4f8f24b25c5d210b40e5647d2ccad19"
#define ShareQQAppId @"1107950218"
#define ShareQQAppSecret @"GRdFDadDBp2fup7J"
#define ShareSinaAppId @"3217814314"
#define ShareSinaAppSecret @"8439d8f0dfb7b87df97df7ee9bad3a01"
#define WeiBoURL @"https://sns.whalecloud.com/sina2/callback"
@implementation GMShareManager
static GMShareManager * _instance = nil;
+(instancetype) shareInstance{
    static dispatch_once_t onceToken ;
    dispatch_once(&onceToken, ^{
        _instance = [[super allocWithZone:NULL] init] ;
        
    }) ;
    return _instance ;
}
+(id) allocWithZone:(struct _NSZone *)zone{
    return [GMShareManager shareInstance] ;
}

-(id) copyWithZone:(struct _NSZone *)zone{
    return [GMShareManager shareInstance] ;
}

//初始化分享
- (void)initShare{
    /**友盟统计*/
//    [UMConfigure initWithAppkey:@"59100454aed17927d400191b" channel:@"App Store"];
    /*
     设置微信的appKey和appSecret
     */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:ShareWXAppId appSecret:ShareWXAppSecret redirectURL:nil];
    /* 设置分享到QQ互联的appID
     * U-Share SDK为了兼容大部分平台命名，统一用appKey和appSecret进行参数设置，而QQ平台仅需将appID作为U-Share的appKey参数传进即可。
     */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:ShareQQAppId appSecret:ShareQQAppSecret redirectURL:nil];
    /*
     设置新浪的appKey和appSecret
     [新浪微博集成说明]http://dev.umeng.com/social/ios/%E8%BF%9B%E9%98%B6%E6%96%87%E6%A1%A3#1_2
     */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:ShareSinaAppId  appSecret:ShareSinaAppSecret redirectURL:WeiBoURL];
}
/**第三方授权登录*/
- (void)LoginWithVC:(id)vc SocialPlatformWithName:(UMSocialPlatformType)platformType response:(void (^)(UMSocialUserInfoResponse * response))Response{
    switch (platformType) {
        case UMSocialPlatformType_WechatSession:{
            [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_WechatSession currentViewController:vc completion:^(id result, NSError *error) {
                if ([result isKindOfClass:[UMSocialUserInfoResponse class]]) {
                    UMSocialUserInfoResponse *resp = result;
                    Response(resp);
                }
            }];
        }
            break;
        case UMSocialPlatformType_QQ:{
            [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_QQ currentViewController:vc completion:^(id result, NSError *error) {
                if ([result isKindOfClass:[UMSocialUserInfoResponse class]]) {
                    UMSocialUserInfoResponse *resp = result;
                    Response(resp);
                }
            }];
        }
            break;
        case UMSocialPlatformType_Sina:{
            [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMSocialPlatformType_Sina currentViewController:vc completion:^(id result, NSError *error) {
                
                if ([result isKindOfClass:[UMSocialUserInfoResponse class]]) {
                    UMSocialUserInfoResponse *resp = result;
                    resp.openid = resp.uid;
                    Response(resp);
                }
            }];
        }
            break;
            
        default:
            break;
    }
}
@end
